package com.kkwrite.regimen.provider.controller.address;

import com.kkwrite.regimen.common.entity.dto.address.RegPositionLogInDTO;
import com.kkwrite.regimen.common.entity.dto.address.RegPositionLogOutDTO;
import com.kkwrite.regimen.provider.service.address.PositionService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by lisha on 2018/7/12 21:25.
 *
 * @author lisha
 */
@RestController
@RequestMapping(value = "/position")
public class PositionLogController {

    @Resource(name = "positionService")
    private PositionService positionService;

    @PostMapping(value = "/saveOrUpdate")
    @HystrixCommand(fallbackMethod = "saveOrUpdateError")
    public RegPositionLogOutDTO saveOrUpdate(@RequestBody RegPositionLogInDTO inDTO) {
        return positionService.saveOrUpdate(inDTO);
    }

    public RegPositionLogOutDTO saveOrUpdateError(RegPositionLogInDTO inDTO) {
        RegPositionLogOutDTO out = new RegPositionLogOutDTO();
        out.setSuccess("false");
        out.setMsg("provider服务异常！");
        return out;
    }

}
